package com.zjeav.lingjiao.ui.register;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.dalimao.corelibrary.swipeback.SwipeBackActivity;
import com.maning.mndialoglibrary.MProgressDialog;
import com.zjeav.lingjiao.R;
import com.zjeav.lingjiao.base.baseBean.BaseActivity;
import com.zjeav.lingjiao.base.baseBean.Result;
import com.zjeav.lingjiao.base.request.ValidateCode;
import com.zjeav.lingjiao.base.response.ValidateCodeResponse;

public class RegisterPhoneActivity extends SwipeBackActivity implements View.OnClickListener, RegisterView {
    EditText phone_ed;
    Button next_bn;
    RegisterPresenter presenter;
    String code;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register_layout);
        phone_ed = findViewById(R.id.phone_ed);
        next_bn = findViewById(R.id.next_bn);
        next_bn.setOnClickListener(this);
        presenter = new RegisterPresenter(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.next_bn:
                if ("".equals(phone_ed.getText().toString())) {
                    Toast.makeText(this, "请输入手机号码", Toast.LENGTH_SHORT).show();
                } else {
                    MProgressDialog.showProgress(this, "获取验证码");
                    presenter.getCode(new ValidateCode(phone_ed.getText().toString(),"1"));
                }
                break;
        }
    }

    @Override
    public void showCodeSuccess(ValidateCodeResponse response) {
        if (MProgressDialog.isShowing()) {
            MProgressDialog.dismissProgress();
        }
        code = response.getData();
        Intent intent = new Intent(this, RegisterActivity.class);
        intent.putExtra("phone", phone_ed.getText().toString());
        intent.putExtra("code", code);
        startActivity(intent);
    }

    @Override
    public void showCodeFail() {
        if (MProgressDialog.isShowing()) {
            MProgressDialog.dismissProgress();
        }
    }

    @Override
    public void registerSuccess(Result result) {

    }
}
